import 'package:flutter/material.dart';
import 'package:ichinesereader/models/report/classlevelchartdata.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:get/get.dart';
import '../../constants.dart';

class ClassLevelWidget extends StatelessWidget {
  ClassLevelWidget({Key? key, required this.levelchartdata}) : super(key: key);
  final List<ClassLevelChartData> levelchartdata;

  @override
  Widget build(BuildContext context) {
    Log.debug('build ClassLevelWidge');
    TooltipBehavior _tooltipbehavior = TooltipBehavior(enable: true);
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    return SfCircularChart(
        title: ChartTitle(
          text: 'Current Class Reading Proficiency'.tr,
          textStyle: isSmallScreen
              ? TextStyle(
                  fontSize: 12.0,
                  color: Get.isDarkMode
                      ? Get.theme.primaryColorDark
                      : Colors.black,
                  fontFamily: 'Montserrat')
              : TextStyle(
                  fontSize: 14.0,
                  color: Get.isDarkMode
                      ? Get.theme.primaryColorDark
                      : Colors.black,
                  fontFamily: 'Montserrat'),
        ),
        legend: Legend(
          isVisible: true,
          textStyle: TextStyle(
              color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.black,
              fontFamily: 'Montserrat'),
        ),
        tooltipBehavior: _tooltipbehavior,
        series: <CircularSeries>[
          PieSeries<ClassLevelChartData, String>(
              dataSource: levelchartdata,
              xValueMapper: (ClassLevelChartData data, _) => data.level,
              yValueMapper: (ClassLevelChartData data, _) => data.value,
              animationDuration: 1000,
              dataLabelSettings: DataLabelSettings(
                isVisible: true,
              ))
        ]);
  }
}
